home *** CD-ROM | disk | FTP | other *** search
/ PC Player 2004 May / pc player 2004-05.iso / Demos / FarCry / Data1.cab / _21B78BF6595C4AE5AC4B64886CDA35CF < prev    next >
Encoding:
Text File  |  2004-01-06  |  2.3 KB  |  71 lines

  1. --------------------------------------------------------------------
  2. -- Description: Blur effect layer for the smoke grenade
  3. -- Created by Marco K÷gler
  4. --------------------------------------------------------------------
  5.  
  6. SmokeBlur = {
  7.     fadeInRate = 1.0,        -- the speed at which it fades in (1.0 units per seconds ... so after 1 second it goes from 0 to 1)
  8.     fadeInScale = 1.0,    -- another scale applied to the fade in rate
  9.     fadeOutRate = 0.1,    -- the speed at which it fades out (0.2 units per seconds ... so after 10 seconds it goes from 0 to 1)
  10.     blurAmount = 0.0,        -- strength of the blur effect
  11. }
  12.  
  13. -------------------------------------------------------
  14. function SmokeBlur:OnInit()
  15. end
  16.  
  17. -------------------------------------------------------
  18. function SmokeBlur:OnActivate()
  19.     self.lastTime = _time;
  20.     self.blurAmount = 0.0;
  21.     self.fadeInScale = 1.0;
  22.     System:SetScreenFx("ScreenBlur", 1);
  23.     
  24.     System:SetScreenFxParamFloat("ScreenBlur", "ScreenBlurAmount", self.blurAmount);
  25.     System:SetScreenFxParamFloat("ScreenBlur", "ScreenBlurColorRed", 1.0);
  26.     System:SetScreenFxParamFloat("ScreenBlur", "ScreenBlurColorGreen", 1.0);
  27.     System:SetScreenFxParamFloat("ScreenBlur", "ScreenBlurColorBlue", 1.0);
  28. end
  29.  
  30. -------------------------------------------------------
  31. function SmokeBlur:OnDeactivate()
  32.     System:SetScreenFx("ScreenBlur", 0);
  33. end
  34.  
  35. -------------------------------------------------------
  36. function SmokeBlur:OnFadeOut()
  37.     local dt = _time - self.lastTime;
  38.     self.lastTime = _time;
  39.     
  40.     self.blurAmount = self.blurAmount - dt * self.fadeOutRate;
  41.     
  42.     if (self.blurAmount < 0.0) then
  43.         self.OnDeactivate();
  44.         return 1;
  45.     end
  46.     
  47.     System:SetScreenFxParamFloat("ScreenBlur", "ScreenBlurAmount", self.blurAmount);
  48. end
  49.  
  50. -----------------------------------------------------
  51. function SmokeBlur:OnUpdate()
  52.     local dt = _time - self.lastTime;
  53.     
  54.     self.blurAmount = self.blurAmount + dt * (self.fadeInRate * self.fadeInScale - self.fadeOutRate);
  55.     
  56.     if (self.blurAmount < 0.0) then
  57.         self.blurAmount = 0.0;
  58.     end
  59.     
  60.     if (self.blurAmount > 1.0) then
  61.         self.blurAmount = 1.0;
  62.     end
  63.     
  64.     System:SetScreenFxParamFloat("ScreenBlur", "ScreenBlurAmount", self.blurAmount);
  65.     -- last call to OnUpdate is deactivation time
  66.     self.lastTime = _time;
  67. end
  68.  
  69. -----------------------------------------------------
  70. function SmokeBlur:OnShutdown()
  71. end